#include <string.h>

#include "interpolate.h"
#include "interpolate_intern.h"



extern void twice_process(
	struct twice_state *s,
	int num_samples_in,
	const int16_t in[],
	int16_t out[])
{
	/* into temp we move the last samples of the previous block
	 * and copy the first samples of the new block to have them
	 * in a continuous buffer. */
	int16_t temp[14];
	int i; /* number of samples to copy, 7 at max */
	i = num_samples_in<7 ? num_samples_in : 7;
	memcpy(temp  ,s->memory,sizeof(s->memory));
	memcpy(temp+7,in,i*sizeof(*temp));

	/* twice internal needs a continuous input sample buffer */
	twice_internal(i,temp,out);
	if (num_samples_in<=7) {
		/* we're done. let's remember the last samples for next time */
		memcpy(s->memory,temp+i,7*sizeof(*temp));
	} else {
		/* for the remaining samples we can now directly
		 * work on the input array */
		twice_internal(num_samples_in-i,in,out+i*2);
		/* we're done. let's remember the last samples for next time */
		memcpy(s->memory,in+(num_samples_in-7),sizeof(s->memory));
	}
}
